/*
    This file is part of the Time-of-Flight Tracer program. It is not part of
    the original PBRT source distribution. See the included license file for
    more information.

    Copyright(c) 2014 Microsoft Corporation

    Author: Phil Pitts
*/

#if defined(_MSC_VER)
#pragma once
#endif

#ifndef PBRT_INTEGRATORS_TOFBIPATH_H
#define PBRT_INTEGRATORS_TOFBIPATH_H

#include "pbrt.h"
#include "integrator.h"
#include "integrators/bipath.h"
#include "integrators/tofpath.h"


class ToFBipathIntegrator : public BipathIntegrator {
public:
	ToFBipathIntegrator(int md, float lambdaMin, float lambdaMax);

	IntegrationResult Li(const Scene *scene, const Renderer *renderer,
        const RayDifferential &ray, const Intersection &isect,
        const Sample *sample, RNG &rng, MemoryArena &arena) const;

private:
	uint32_t GeneratePath(PathData &data, const RayDifferential r,
		const Intersection &firstIsect, const Sample* sample, ToFPathVertex *path,
		RayDifferential *escapedRay, Spectrum *escapedAlpha) const;
	void SaveToFVertexInfo(ToFPathVertex *v, int pathIdx,
		const RayDifferential &ray) const;
	uint32_t GenerateLightPath(PathData &data, const RayDifferential r,
		const Sample* sample, const Spectrum &a, ToFPathVertex *path) const;
	Spectrum DirectLightingVertex(PathData &data, const Sample *sample,
		int pathIdx, const ToFPathVertex &v, float *light2isect) const;
	Spectrum LightPathL(PathData &data, const Sample &sample,
		ToFPathVertex* lightPath, const ToFPathVertex &vc,
		int *nSpecularVertices, int cameraPathIdx, int lightPathIdx) const;

	float lambdaMin, lambdaMax;
};


ToFBipathIntegrator *CreateToFBipathSurfaceIntegrator(const ParamSet &params);

#endif // PBRT_INTEGRATORS_TOFBIPATH_H
